<template>
	<div class="layout-flex">
		<div class="tabHeader">
			<el-tabs v-model="state.activeName" class="header-tabs" @tab-change="handleChange">
				<el-tab-pane v-for="tab in state.headerTabsList" :key="tab.value" :label="tab.label" :name="tab.value"></el-tab-pane>
			</el-tabs>
		</div>
		<FastFilter @search="toRefresh" @reset="resetList">
			<template v-slot:leftFilters>
				<!-- 公司主体和团队 -->
				<CompanySelect @change="handleSearch($event, 'companyIds')" v-model="state.queryForm.companyIds" class="w180" :teamRef="teamSelectRef" />
				<TeamSelect @change="handleSearch($event, 'teamIds')" v-model="state.queryForm.teamIds" class="w180" ref="teamSelectRef" />
				<!-- 仓库 -->
				<WareSelect @change="handleSearch($event, 'whIds')" v-model="state.queryForm.whIds" mode="2" title="仓库" class="w180" />

				<!-- 库区 -->
				<FunctionalSelect
					v-show="state.activeName === '2'"
					v-model="state.queryForm.areaIds"
					:optionFormat="{
						key: 'areaId',
						label: 'areaName',
					}"
					useRadio
					:options="state.warehouseAreaList"
					placeholder="库区"
					@query-list="handleSearch($event, 'areaIds')"
					class="w180"
				/>
				<!-- 库位 -->
				<FunctionalSelect
					v-show="state.activeName === '2'"
					v-model="state.queryForm.positionIds"
					:optionFormat="{
						key: 'positionId',
						label: 'positionCode',
					}"
					useRadio
					:options="state.warehouseSeatList"
					placeholder="库位"
					@query-list="handleSearch($event, 'positionIds')"
					class="w180"
				/>

				<!-- 备货区域 -->
				<StockAreaSelect @change="handleSearch($event, 'stockupAreaCodes')" v-model="state.queryForm.stockupAreaCodes" class="w180" />
				<!-- 备货平台 -->
				<StockPlatformSelect
					v-if="state.activeName !== '0'"
					@change="handleSearch($event, 'stockupPlatformCodes')"
					v-model="state.queryForm.stockupPlatformCodes"
					class="w180"
				/>
				<template v-if="state.activeName === '1'">
					<!-- 供应商 -->
					<el-select
						style="width: 202px"
						v-model="state.queryForm.supplierIds"
						filterable
						:filter-method="supplierFilterMethod"
						placeholder="供应商"
						multiple
						:loading="state.supplierFilterloading"
						@change="toRefresh"
						:collapse-tags="true"
						clearable
					>
						<el-option v-for="item in state.filterSupplierList" :key="item.supplierId" :label="item.supplierName" :value="item.supplierId">
							<div style="display: flex; justify-content: space-between; gap: 16px">
								<span>{{ item.supplierName }}</span>
								<span>{{ item.supplierCode }}</span>
							</div>
						</el-option>
					</el-select>
					<!-- 产品质量 -->
					<el-select v-model="state.queryForm.qualityType" placeholder="产品质量" clearable style="width: 100px" @change="toRefresh">
						<el-option v-for="item in state.qualityTypeList" :key="item.value" :label="item.label" :value="item.value">{{ item.label }}</el-option>
					</el-select>
					<!-- 是否赠品 -->
					<el-select v-model="state.queryForm.giftFlag" placeholder="是否赠品" clearable style="width: 100px" @change="toRefresh">
						<el-option v-for="item in state.giftFlagList" :key="item.value" :label="item.label" :value="item.value">{{ item.label }}</el-option>
					</el-select>
				</template>

				<!-- 分类 -->
				<CategorySelect v-show="state.activeName !== '2'" @change="handleSearch($event, 'categoryIdList')" v-model="state.queryForm.categoryIdList" />
				<!-- 品牌 -->
				<BrandListSelect v-show="state.activeName !== '2'" @change="handleSearch($event, 'skuBrandList')" v-model="state.queryForm.skuBrandList" />
				<!-- 产品状态 -->
				<el-select
					v-show="state.activeName !== '2'"
					v-model="state.queryForm.skuOpenStatus"
					placeholder="产品状态"
					clearable
					style="width: 100px"
					@change="toRefresh"
				>
					<el-option v-for="item in state.skuOpenStatusList" :key="item.value" :label="item.label" :value="item.value">{{ item.label }}</el-option>
				</el-select>

				<!-- 采购单号 -->
				<ComboSearch
					v-show="state.activeName === '1'"
					:options="state.comboSearchOpt2"
					:prefixSelect="'purchaseOrderCode'"
					@search="handleComboSearch($event, 'purchaseSearchDto')"
					ref="comboSearchRef2"
				/>
				<!-- sku -->
				<ComboSearch :options="state.comboSearchOpt" :prefixSelect="'sku'" @search="handleComboSearch($event, 'skuSearchDto')" ref="comboSearchRef" />
				<!-- 采购日期 -->
				<date-picker-with-prefix v-if="state.activeName === '1'" :options="state.datePickerOptions" @change="changeDataRange" ref="datePickerRef" />
			</template>
			<template #result>
				<FilterTag
					v-for="(item, index) in FilterTagOption"
					:key="index"
					:show="item.key()"
					:label="item.label()"
					:value="item.value()"
					@close="closeTag(item.clear)"
				/>
			</template>
		</FastFilter>
		<div class="layout-padding">
			<FastTableHandle @queryTable="toRefresh(false)">
				<template v-slot:leftBtns>
					<!-- 0 -->
					<el-button v-if="state.activeName === '0' && getAuth('wms_wmsInventorySummary_update')" type="primary" @click="toCaculateProductStockAge"
						>更新库龄</el-button
					>
					<!-- 1 -->
					<el-button
						v-if="state.activeName === '1' && getAuth('wms_InventoryBatchRecord_import')"
						type="primary"
						@click="fileUploadRef.dialogControl()"
					>
						导入初始化库存
					</el-button>
					<!-- 2 -->
					<template v-if="state.activeName === '2'">
						<el-button type="primary" @click="toOpenSeatTransferDialog" v-if="getAuth('wms_wmsInventoryPosition_view')">库位转移</el-button>
						<el-dropdown class="ml10" @command="toCopy">
							<el-button>
								打印操作
								<el-icon class="el-icon--right">
									<arrow-down />
								</el-icon>
							</el-button>
							<template #dropdown>
								<!-- <el-dropdown-menu>
									<el-dropdown-item command="1">打印产品条码</el-dropdown-item>
									<el-dropdown-item command="2">打印FNSKU条码</el-dropdown-item>
								</el-dropdown-menu> -->
							</template>
						</el-dropdown>
						<span class="ml10" v-if="state.checkedList.length > 0" style="color: #a6abb4"
							>已选 <span style="color: #005bf5">{{ state.checkedList.length }}</span> 条数据</span
						>
					</template>
				</template>

				<template v-slot:rightWrapper>
					<el-checkbox v-model="state.queryForm.isHideZero" true-label="1" false-label="0" label="隐藏0库存数据" size="large" @change="toRefresh" />
					<el-icon
						v-if="state.activeName === '1' && getAuth('wms_wmsInventoryBatchRecord_view')"
						style="cursor: pointer"
						@click="initRecordDialogRef.openDialog()"
					>
						<List />
					</el-icon>
					<el-icon v-if="getAuth('wms_wmsInventorySummary_export') && state.activeName === '0'" style="cursor: pointer" @click="toExport">
						<Download />
					</el-icon>
					<el-icon v-if="getAuth('wms_wmsInventoryBatch_export') && state.activeName === '1'" style="cursor: pointer" @click="toExport">
						<Download />
					</el-icon>
					<el-icon v-if="getAuth('wms_wmsInventoryPosition_export') && state.activeName === '2'" style="cursor: pointer" @click="toExport">
						<Download />
					</el-icon>
					<el-icon
						style="cursor: pointer"
						@click="
							state.activeName === '1'
								? columnsSettingRef_1.openDialog()
								: state.activeName === '2'
								? columnsSettingRef_2.openDialog()
								: state.activeName === '0'
								? columnsSettingRef.openDialog()
								: ''
						"
					>
						<Setting />
					</el-icon>
				</template>
			</FastTableHandle>
			<proList v-if="state.activeName === '0'" :queryForm="state.queryForm" :thList="columnsData.proList" ref="proListRef" />
			<batchList v-if="state.activeName === '1'" :queryForm="state.queryForm" :thList="columnsData.batchList" ref="batchListRef" />
			<seatList
				v-if="state.activeName === '2'"
				:queryForm="state.queryForm"
				:thList="columnsData.seatList"
				ref="seatListRef"
				@updateCheckedList="updateCheckedList"
			/>
		</div>
		<ColumnsSetting
			v-if="state.activeName === '0'"
			ref="columnsSettingRef"
			@changeColumn="changeColumn"
			:allList="columns['proList']"
			:commitName="'proList'"
			:list="columnsData['proList']"
		/>
		<ColumnsSetting
			v-if="state.activeName === '1'"
			ref="columnsSettingRef_1"
			@changeColumn="changeColumn_1"
			:allList="columns['batchList']"
			:commitName="'batchList'"
			:list="columnsData['batchList']"
		/>
		<ColumnsSetting
			v-if="state.activeName === '2'"
			ref="columnsSettingRef_2"
			@changeColumn="changeColumn_2"
			:allList="columns['seatList']"
			:commitName="'seatList'"
			:list="columnsData['seatList']"
		/>
		<seatTransferDialog :seatTransferList="state.checkedList" ref="seatTransferDialogRef" @toRefresh="toRefresh" />
		<initRecordDialog ref="initRecordDialogRef" />
		<FileUploadTemplate
			ref="fileUploadRef"
			:downloadUrl="downloadTemplate.downloadUrl"
			:uploadUrl="downloadTemplate.uploadUrl"
			:title="downloadTemplate.title"
			:fileName="downloadTemplate.fileName"
			:configName="downloadTemplate.configName"
			:fileType="['xlsx', 'xls']"
			@close="toRefresh"
		>
			<template #expression>
				<ul class="list-disc pl20 text-xs">
					<li class="mt10">所属仓库: 请填写<span style="color: red">仓库代码</span></li>
					<li class="mt8">采购日期：<span style="color: red">未填写时系统默认为当前操作时间</span></li>
					<li class="mt8">产品质量：<span style="color: red">未填写时系统默认为“良品”</span></li>
					<li class="mt8">是否赠品：<span style="color: red">未填写时系统默认为“非赠品”</span></li>
					<li class="mt8">入库日期：<span style="color: red">未填写时系统默认为当前操作时间</span></li>
					<li class="mt8">
						良品、次品要分开2条记录录入:当产品质量录入"良品”时，填写良品的在库数量和存放库位;当产品质量录入为"次品”时，填写次品的在库数量和存放库位
					</li>
					<li class="mt8">相同批次的只能有一条记录，批次属性请尽量完善，如果出现批次属性内容相同的记录会导入失败;</li>
				</ul>
			</template>
			<template #column>
				<el-table-column label="行号" prop="rowNum"></el-table-column>
				<el-table-column label="失败原因" prop="msg"></el-table-column>
			</template>
		</FileUploadTemplate>
		<copyDialog ref="copyDialogRef" />
	</div>
</template>
<script lang="ts" setup  name="productInventory">
import { ElMessage } from 'element-plus';
import { Local } from '/@/utils/storage';
const ColumnsSetting = defineAsyncComponent(() => import('../columnsSetting/index.vue'));
import { columns } from '../columnsSetting/columns.js';

import { getwhTree, getPlatformList, sysStockArea } from '/@/api/transferSlip/index';
import { treeQuery } from '/@/api/product/classification';
import { pageList as brandList } from '/@/api/product/brand';
import { searchBySupplierName } from '/@/api/product/auxiliaryMaterial';
import { pageList as warehouseArea } from '/@/api/warehouseSetting/warehouseRange';
import { pageList as warehouseSeat } from '/@/api/warehouseSetting/warehouseSeat';
import { wmsStockSummaryExport, wmsInventoryBatchExport, wmsInventoryPositionExport, caculateProductStockAge } from '/@/api/inventory/index';
// import { useDict } from '/@/hooks/dict';
// const { stocking_area } = useDict('stocking_area');
const proList = defineAsyncComponent(() => import('./proList.vue'));
const batchList = defineAsyncComponent(() => import('./batchList.vue'));
const seatList = defineAsyncComponent(() => import('./seatList.vue'));
const seatTransferDialog = defineAsyncComponent(() => import('./component/seatTransferDialog.vue'));
const initRecordDialog = defineAsyncComponent(() => import('./component/initRecordDialog.vue'));
const copyDialog = defineAsyncComponent(() => import('./component/copyDialog/index.vue'));
import { auth } from '/@/utils/authFunction';
const getAuth = (value: string) => {
	return auth(value);
};
const obj = {
	companyIds: [],
	teamIds: [],
	whIds: [],
	stockupAreaCodes: [],
	categoryIdList: [],
	supplierIds: [],
	skuBrandList: [],
	skuOpenStatus: '',
	skuSearchDto: {
		searchFieldId: '',
		searchMode: '',
		searchValue: '',
		searchValueList: [],
	},
	purchaseSearchDto: {
		searchFieldId: '',
		searchMode: '',
		searchValue: '',
		searchValueList: [],
	},

	stockupPlatformCodes: [],
	areaIds: [],
	positionIds: [],
	isHideZero: '1',
	purchaseStartTimestamp: '',
	purchaseEndTimestamp: '',
	stockInStartTimestamp: '',
	stockInEndTimestamp: '',
};
const state = reactive({
	supplierFilterloading: false,
	activeName: '0',
	headerTabsList: [
		{ label: '产品库存', value: '0' },
		{ label: '批次库存', value: '1' },
		{ label: '库位库存', value: '2' },
	],

	whList: [],
	classificationList: [],
	brandTypeOptions: [],
	skuOpenStatusList: [
		{ label: '启用', value: '0' },
		{ label: '禁用', value: '1' },
	],
	qualityTypeList: [
		{ label: '良品', value: '1' },
		{ label: '次品', value: '2' },
		{ label: '废品', value: '3' },
	],
	giftFlagList: [
		{ label: '赠品', value: '0' },
		{ label: '非赠品', value: '1' },
	],
	comboSearchOpt: [
		{ label: '产品名称', key: 'prodName' },
		{ label: 'SKU', key: 'sku' },
		{ label: 'MSKU', key: 'msku' },
		{ label: 'FNSKU', key: 'fnsku' },
	],
	comboSearchOpt2: [
		{ label: '采购单号', key: 'purchaseOrderCode' },
		{ label: '初始批次号', key: 'initBatchCode' },
	],
	datePickerOptions: [
		{ label: '采购日期', value: 1 },
		{ label: '入库日期', value: 2 },
	],
	supplierList: [],
	filterSupplierList: [],
	platList: [],
	warehouseAreaList: [],
	warehouseSeatList: [],
	areaList: [],
	checked: true,
	queryForm: Object.assign({}, obj),
	checkedList: [],
});
const comboSearchRef = ref();
const comboSearchRef2 = ref();
const datePickerRef = ref();
const columnsSettingRef = ref();
const columnsSettingRef_1 = ref();
const columnsSettingRef_2 = ref();
const proListRef = ref();
const batchListRef = ref();
const seatListRef = ref();
const seatTransferDialogRef = ref();
const initRecordDialogRef = ref();
const fileUploadRef = ref();
const copyDialogRef = ref();
const downloadTemplate = reactive({
	title: '导入初始化库存',
	downloadUrl: '',
	uploadUrl: '/wms/wmsInventoryBatchRecord/import/batch',
	fileName: '',
	configName: 'wms-batch-import',
});
const updateCheckedList = (list) => {
	state.checkedList = list;
};
// 列设置
const columnsData = reactive({
	proList: Local.get('proList') || columns.proList,
	batchList: Local.get('batchList') || columns.batchList,
	seatList: Local.get('seatList') || columns.seatList,
});
const changeColumn = (list) => {
	columnsData.proList = list;
};
const changeColumn_1 = (list) => {
	columnsData.batchList = list;
};
const changeColumn_2 = (list) => {
	columnsData.seatList = list;
};

const teamSelectRef = ref();

const filterTags = reactive({
	companyIds: [],
	teamIds: [],
	whIds: [],
	stockupAreaCodes: [],
	stockupPlatformCodes: [],
	categoryIdList: [],
	skuBrandList: [],
});
const FilterTagOption = [
	{
		key: () => state.queryForm.companyIds.length,
		label: () => '公司主体',
		value: () => filterTags.companyIds.map((item) => item.name),
		clear: () => {
			state.queryForm.companyIds = [];
		},
	},
	{
		key: () => state.queryForm.teamIds.length,
		label: () => '团队',
		value: () => filterTags.teamIds.map((item) => item.name),
		clear: () => {
			state.queryForm.teamIds = [];
		},
	},
	{
		key: () => state.queryForm.whIds.length,
		label: () => '仓库',
		value: () => filterTags.whIds.map((item) => item.nodeName),
		clear: () => {
			state.queryForm.whIds = [];
		},
	},
	{
		key: () => (state.activeName === '2' ? state.queryForm.areaIds.length : 0),
		label: () => '库区',
		value: () => state.warehouseAreaList.filter((item) => state.queryForm.areaIds.indexOf(item.areaId) !== -1).map((item) => item.areaName),
		clear: () => {
			state.queryForm.areaIds = [];
		},
	},
	{
		key: () => (state.activeName === '2' ? state.queryForm.positionIds.length : 0),
		label: () => '库位',
		value: () =>
			state.warehouseSeatList.filter((item) => state.queryForm.positionIds.indexOf(item.positionId) !== -1).map((item) => item.positionCode),
		clear: () => {
			state.queryForm.positionIds = [];
		},
	},
	{
		key: () => state.queryForm.stockupAreaCodes.length,
		label: () => '备货区域',
		value: () => filterTags.stockupAreaCodes.map((item) => item.label),
		clear: () => {
			state.queryForm.stockupAreaCodes = [];
		},
	},
	{
		key: () => (state.activeName !== '0' ? state.queryForm.stockupPlatformCodes.length : 0),
		label: () => '备货平台',
		value: () => filterTags.stockupPlatformCodes.map((item) => item.platformName),
		clear: () => {
			state.queryForm.stockupPlatformCodes = [];
		},
	},
	{
		key: () => (state.activeName === '1' ? state.queryForm.supplierIds.length : 0),
		label: () => '供应商',
		value: () =>
			state.filterSupplierList.filter((item) => state.queryForm.supplierIds.indexOf(item.supplierId) !== -1).map((item) => item.supplierName),
		clear: () => {
			state.queryForm.supplierIds = [];
		},
	},
	{
		key: () => (state.activeName !== '2' ? state.queryForm.categoryIdList.length : 0),
		label: () => '产品品类',
		value: () => filterTags.categoryIdList.map((item) => item.label),
		clear: () => {
			state.queryForm.categoryIdList = [];
		},
	},
	{
		key: () => (state.activeName !== '2' ? state.queryForm.skuBrandList.length : 0),
		label: () => '品牌',
		value: () => filterTags.skuBrandList.map((item) => item.brandName),
		clear: () => {
			state.queryForm.skuBrandList = [];
		},
	},
	{
		key: () => state.queryForm.skuSearchDto?.searchFieldId,
		label: () => state.comboSearchOpt.find((item) => item.key === state.queryForm.skuSearchDto?.searchFieldId)?.label,
		value: () => state.queryForm.skuSearchDto?.searchValueList,
		clear: () => {
			state.queryForm.skuSearchDto = {};
			comboSearchRef?.value?.resetFields();
		},
	},
	{
		key: () => (state.activeName === '1' ? state.queryForm.purchaseSearchDto?.searchFieldId : ''),
		label: () => state.comboSearchOpt2.find((item) => item.key === state.queryForm.purchaseSearchDto?.searchFieldId)?.label,
		value: () => state.queryForm.purchaseSearchDto?.searchValueList,
		clear: () => {
			state.queryForm.purchaseSearchDto = {};
			comboSearchRef2?.value?.resetFields();
		},
	},
];
const closeTag = (clear) => {
	clear();
	toRefresh();
};
onMounted(() => {
	getwhTreeOpt();
	getClassificationList();
	getBrandList();
	getsupplierIds();
	getPlatformOpt();
	getStockArea();
});
const toOpenSeatTransferDialog = () => {
	if (state.checkedList.length === 0) {
		ElMessage({
			message: '请选择操作的数据',
			type: 'error',
		});
	} else {
		seatTransferDialogRef.value.openDialog();
	}
};
const toCaculateProductStockAge = () => {
	caculateProductStockAge()
		.then(() => {
			ElMessage({
				message: '库龄更新成功',
				type: 'success',
			});
			toRefresh();
		})
		.catch((res) => {
			ElMessage({
				message: res.msg,
				type: 'error',
			});
		});
};
const handleChange = () => {
	state.checkedList = [];
};
const toRefresh = (v) => {
	if (state.activeName === '0') {
		proListRef.value?.toRefresh(v);
	}
	if (state.activeName === '1') {
		batchListRef.value?.toRefresh(v);
	}
	if (state.activeName === '2') {
		seatListRef.value?.toRefresh(v);
	}
};
const resetList = () => {
	Object.keys(obj).forEach((i) => {
		state.queryForm[i] = obj[i];
	});
	comboSearchRef.value?.resetFields();
	comboSearchRef2.value?.resetFields();
	toRefresh();
};
// 备货区域
const getStockArea = async () => {
	const { data } = await sysStockArea();
	state.areaList = data;
};

// 分类
const getClassificationList = async () => {
	const { data } = await treeQuery({});
	state.classificationList = formatClassTree(data);
};
// 初始化分类树形结构
const formatClassTree = (data) => {
	return data.map((item) => {
		item.key = item.id;
		if (item.children) {
			item.children = formatClassTree(item.children);
		}
		return item;
	});
};
// 仓库
const getwhTreeOpt = async () => {
	const { data } = await getwhTree({});
	state.whList = formatWhTree(data);
};
// 初始化仓库树形结构
const formatWhTree = (data) => {
	return data.map((item) => {
		item.key = item.nodeCode;
		item.label = item.nodeName;
		if (item.children) {
			item.children = formatWhTree(item.children);
		}
		return item;
	});
};
// 品牌
const getBrandList = async () => {
	const { data } = await brandList({ current: 1, size: 1000 });
	state.brandTypeOptions = data.records;
};
// 供应商
const getsupplierIds = async () => {
	const { data } = await searchBySupplierName();
	state.supplierList = JSON.parse(JSON.stringify(data));
	state.filterSupplierList = JSON.parse(JSON.stringify(data));
};
const supplierFilterMethod = (query) => {
	if (query) {
		state.supplierFilterloading = true;

		state.filterSupplierList = state.supplierList.filter((item) => {
			return item.supplierCode.toLowerCase().includes(query.toLowerCase()) || item.supplierName.toLowerCase().includes(query.toLowerCase());
		});
		state.supplierFilterloading = false;
	} else {
		state.filterSupplierList = state.supplierList;
	}
};
//平台
const getPlatformOpt = async () => {
	const { data } = await getPlatformList();
	state.platList = data;
};
// 库区
const getWarehouseArea = () => {
	state.warehouseAreaList = [];
	if (state.queryForm.whIds.length > 0) {
		state.queryForm.whIds.forEach(async (wh) => {
			const { data } = await warehouseArea({ whId: wh });
			state.warehouseAreaList = [...state.warehouseAreaList, ...data.records];
		});
	}
	state.queryForm.areaIds = [];
};
// 库位
const getWarehouseSeat = () => {
	state.warehouseSeatList = [];
	if (state.queryForm.areaIds.length > 0) {
		state.queryForm.areaIds.forEach(async (item) => {
			let d = state.warehouseAreaList.find((it) => {
				if (it.areaId === item) {
					return it;
				}
			});
			const { data } = await warehouseSeat({ areaCode: d.areaCode });
			state.warehouseSeatList = [...state.warehouseSeatList, ...data.records];
		});
	}
	state.queryForm.positionIds = [];
};
const handleSearch = (data, type) => {
	const { ids, list } = data;
	filterTags[type] = list;
	// 联动
	if (type == 'companyIds') {
		state.queryForm.teamIds = [];
	}
	if (type === 'whIds') {
		getWarehouseArea();
		getWarehouseSeat();
	}
	if (type === 'areaIds') {
		getWarehouseSeat();
	}
	toRefresh();
};
const handleComboSearch = (ids, type) => {
	state.queryForm[type] = {};
	const { key, like, value } = ids;
	state.queryForm[type].searchFieldId = key;
	state.queryForm[type].searchValue = like;
	state.queryForm[type].searchValueList = value;
	state.queryForm[type].searchMode = value.length ? 'mode_in' : 'mode_like';

	toRefresh();
};

const changeDataRange = (val: unknown, v2: string[]) => {
	if (val === 1) {
		state.queryForm.stockInStartTimestamp = '';
		state.queryForm.stockInEndTimestamp = '';
		state.queryForm.purchaseStartTimestamp = v2[0] ? v2[0] + ' 00:00:00' : '';
		state.queryForm.purchaseEndTimestamp = v2[1] ? v2[1] + ' 23:59:59' : '';
	} else {
		state.queryForm.stockInStartTimestamp = v2[0] ? v2[0] + ' 00:00:00' : '';
		state.queryForm.stockInEndTimestamp = v2[1] ? v2[1] + ' 23:59:59' : '';
		state.queryForm.purchaseStartTimestamp = '';
		state.queryForm.purchaseEndTimestamp = '';
	}
	toRefresh();
};
const toExport = () => {
	try {
		if (state.activeName === '0') {
			wmsStockSummaryExport({ query: state.queryForm }).then(() => {
				ElMessage({
					message: '产品库存下载成功，请至【下载中心】下载查看',
					type: 'success',
				});
			});
		}
		if (state.activeName === '1') {
			wmsInventoryBatchExport({ query: state.queryForm }).then(() => {
				ElMessage({
					message: '批次库存下载成功，请至【下载中心】下载查看',
					type: 'success',
				});
			});
		}
		if (state.activeName === '2') {
			wmsInventoryPositionExport({ query: state.queryForm }).then(() => {
				ElMessage({
					message: '库位库存下载成功，请至【下载中心】下载查看',
					type: 'success',
				});
			});
		}
	} catch (res) {
		ElMessage({
			message: res.msg,
			type: 'error',
		});
	}
};
const toCopy = (v) => {
	if (state.checkedList.length === 0) {
		ElMessage({
			message: '请选择打印的数据',
			type: 'error',
		});
	} else {
		copyDialogRef.value.openDialog(v);
	}
};
</script>
<style scoped>
.tabHeader {
	padding: 0 20px 0 20px;
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 1px solid #efefef;
}
.header-tabs :deep(.el-tabs__header) {
	margin-bottom: 0;
}
:deep(.fast-tabel-handle .right-content .base-right) {
	align-items: center;
}
</style>
